using System.Data;
using AnhAnh;
using AutoSales;
using System;
using System.ComponentModel;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Drawing;
using System.Linq;
using System.Resources;
using System.Windows.Forms;

public sealed class FormSetting : Form
{
	private IContainer icontainer_0;

	private GroupBox groupBox1;

	private Label label9;

	private Label label8;

	private TextBox textBoxPassword;

	private TextBox textBoxUserName;

	private CheckBox checkBoxAutoRun;

	private Button buttonSave;

	public FormSetting(FormMain formMain_0)
	{
		this.InitializeComponent();
	}

	private void buttonSave_Click(object sender, EventArgs e)
	{
		Setting setting = new Setting();
		setting.UserName=(this.textBoxUserName.Text);
		setting.Password=(Anh.Encrypt(this.textBoxPassword.Text));
		setting.AutoStartup=(this.checkBoxAutoRun.Checked);
		Setting setting1 = setting;
		if (!UI.ValidateUserEntry(setting1))
		{
			return;
		}
		AutoSalesContext autoSalesContext = new AutoSalesContext();
		if (autoSalesContext.Settings.Count<Setting>() != 0)
		{
			Setting setting2 = autoSalesContext.Settings.FirstOrDefault<Setting>();
			setting2.UserName=(this.textBoxUserName.Text);
			setting2.Password=(Anh.Encrypt(this.textBoxPassword.Text));
			setting2.AutoStartup=(this.checkBoxAutoRun.Checked);
			autoSalesContext.Entry<Setting>(setting2).State = EntityState.Modified;
		}
		else
		{
			autoSalesContext.Settings.Add(setting1);
		}
		autoSalesContext.SaveChanges();
		FormMain.mAnh.AutoRun(this.checkBoxAutoRun.Checked);
		base.Close();
	}

	protected override void Dispose(bool bool_0)
	{
		if (bool_0 && this.icontainer_0 != null)
		{
			this.icontainer_0.Dispose();
		}
		base.Dispose(bool_0);
	}

	private void FormSetting_Shown(object sender, EventArgs e)
	{
		AutoSalesContext autoSalesContext = new AutoSalesContext();
		if (autoSalesContext.Settings.Count<Setting>() > 0)
		{
			Setting setting = autoSalesContext.Settings.FirstOrDefault<Setting>();
			this.textBoxUserName.Text = setting.UserName;
			this.textBoxPassword.Text = Anh.Decrypt(setting.Password);
			this.checkBoxAutoRun.Checked = setting.AutoStartup;
		}
	}

	private void InitializeComponent()
	{
		ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(FormSetting));
		this.groupBox1 = new GroupBox();
		this.label9 = new Label();
		this.label8 = new Label();
		this.textBoxPassword = new TextBox();
		this.textBoxUserName = new TextBox();
		this.checkBoxAutoRun = new CheckBox();
		this.buttonSave = new Button();
		this.groupBox1.SuspendLayout();
		base.SuspendLayout();
		this.groupBox1.Controls.Add(this.label9);
		this.groupBox1.Controls.Add(this.label8);
		this.groupBox1.Controls.Add(this.textBoxPassword);
		this.groupBox1.Controls.Add(this.textBoxUserName);
		this.groupBox1.Location = new Point(12, 12);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(294, 68);
		this.groupBox1.TabIndex = 0;
		this.groupBox1.TabStop = false;
		this.groupBox1.Text = "Facebook Account";
		this.label9.AutoSize = true;
		this.label9.Location = new Point(151, 21);
		this.label9.Name = "label9";
		this.label9.Size = new System.Drawing.Size(53, 13);
		this.label9.TabIndex = 52;
		this.label9.Text = "Password";
		this.label8.AutoSize = true;
		this.label8.Location = new Point(9, 21);
		this.label8.Name = "label8";
		this.label8.Size = new System.Drawing.Size(57, 13);
		this.label8.TabIndex = 51;
		this.label8.Text = "UserName";
		this.textBoxPassword.Location = new Point(154, 37);
		this.textBoxPassword.Name = "textBoxPassword";
		this.textBoxPassword.PasswordChar = '*';
		this.textBoxPassword.Size = new System.Drawing.Size(127, 20);
		this.textBoxPassword.TabIndex = 2;
		this.textBoxUserName.Location = new Point(12, 37);
		this.textBoxUserName.Name = "textBoxUserName";
		this.textBoxUserName.Size = new System.Drawing.Size(127, 20);
		this.textBoxUserName.TabIndex = 1;
		this.checkBoxAutoRun.AutoSize = true;
		this.checkBoxAutoRun.Location = new Point(24, 86);
		this.checkBoxAutoRun.Name = "checkBoxAutoRun";
		this.checkBoxAutoRun.Size = new System.Drawing.Size(116, 17);
		this.checkBoxAutoRun.TabIndex = 3;
		this.checkBoxAutoRun.Text = "Auto run on startup";
		this.checkBoxAutoRun.UseVisualStyleBackColor = true;
		this.buttonSave.Location = new Point(232, 86);
		this.buttonSave.Name = "buttonSave";
		this.buttonSave.Size = new System.Drawing.Size(75, 30);
		this.buttonSave.TabIndex = 6;
		this.buttonSave.Text = "Save";
		this.buttonSave.UseVisualStyleBackColor = true;
		this.buttonSave.Click += new EventHandler(this.buttonSave_Click);
		base.AcceptButton = this.buttonSave;
		base.AutoScaleDimensions = new SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(319, 126);
		base.Controls.Add(this.groupBox1);
		base.Controls.Add(this.buttonSave);
		base.Controls.Add(this.checkBoxAutoRun);
		base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
		base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "FormSetting";
		base.ShowInTaskbar = false;
		base.StartPosition = FormStartPosition.CenterParent;
		this.Text = "Setting";
		base.Shown += new EventHandler(this.FormSetting_Shown);
		this.groupBox1.ResumeLayout(false);
		this.groupBox1.PerformLayout();
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}